<?php

namespace app\index\controller;

use think\Controller;
use think\Request;
use think\Db;
class Lists extends Common
{
    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index()
    {   $cid=(int)input('id');
        $cate=db('cate')->where('id',$cid)->find();//当前栏目信息
        if ($cate['pid']==0) {
            $cates=db('cate')->where('pid',$cid)->select();
            static $ids=array();//所有二级栏目id
            foreach ($cates as $k => $v) {
               $ids[]=$v['id'];
            }
            $cid=$ids[0];
        $cate=db('cate')->where('id',$cid)->find();//当前栏目信息
        }
        $pos=$this->getPos($cid);
        $artRes=model('Archives')->where('cid',$cid)->paginate(10);//当前栏目下的所有文章
        $curr=$this->getTopId($cid);//顶级栏目id
        $topcate=db('cate')->find($curr);//顶级栏目信息
        $level=db('cate')->where('pid',$curr)->select();
        $temp=$cate['list_tmp'];//获取当前栏目模板
        $this->assign([
            'cid'=>$cid,
            'curr'=>$curr,
            'level'=>$level,
            'pos'=>$pos,
            'cate'=>$cate,
            'artRes'=>$artRes,
            'topcate'=>$topcate,
        ]);
        return $this->fetch($this->temp.'/'.$temp);
    }

    
}
